<template>
	<view>
		<view class="wid90 mar">
			<view class="hei20"></view>
			<view class="borRad40 dis disAl disJuC foSi25 hei60 coFFF mar foSi28" @click="fanhui"
				style="background: linear-gradient(to right, #fb8480, #fa3f86);width: 240rpx;">返回首页</view>
			<view style="height: 40rpx;"></view>
			<rich-text  :selectable="true" :nodes="mianze" style="-webkit-user-select: text;-moz-user-select: text;-ms-user-select: text;user-select: text;"></rich-text>
			<view v-if="list" class="wid100 mar20" style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);padding: 40rpx 0;">
				<view class="wid90 mar">
					<view class="foSi40 fowe600">{{list.name}}</view>
					<view class="mar-top30 dis disAl disJuB">
						<view class="dis disAl">
							<image src="../../static/zhImg01.png" style="width: 30rpx;height: 30rpx;"></image>
							<view class="mar-left20 foSi28">{{list.uname}}</view>
						</view>
						<view class="hei60 dis disAl disJuC borRad40 foSi28" @click="fuzhi(1)"
							style="width: 220rpx;background-color: #77c2c5;">复制</view>
					</view>
					<view class="mar-top30 dis disAl disJuB">
						<view class="dis disAl">
							<image src="../../static/mima.png" style="width: 30rpx;height: 30rpx;"></image>
							<view class="mar-left20 foSi28">*********</view>
						</view>
						<view class="hei60 dis disAl disJuC borRad40 foSi28" @click="fuzhi(2)"
							style="width: 220rpx;background-color: #77c2c5;">复制</view>
					</view>
				</view>
			</view>
			<rich-text  :selectable="true" :nodes="data" style="-webkit-user-select: text;-moz-user-select: text;-ms-user-select: text;user-select: text;"></rich-text>
			<view style="height: 40rpx;"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data:'',
				mianze: '',
				list: null,
				id: null
			}
		},
		onShow() {
			// 校验兑换码是否过期
			if(uni.getStorageSync('get_type_dhm') == 1){
				// 使用了兑换码，看兑换码有没有效哦
				this.check_code()
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getList()
		},
		methods: {
			check_code(){
				var that = this
				uni.request({
					url: this.global.url+'api/zy/check_code_status',
					method: 'POST',
					data: {
						code:uni.getStorageSync('dhm')
					},
					success: (res) => {
						let result = res.data
						if (result.code == 1) {
							if(result.data ==  0){
								uni.showToast({
									title:'兑换码已失效',
									icon:'error'
								})
								setTimeout(()=>{
									uni.redirectTo({
										url:'/pages/h5/index/index'
									})
								},1000)
							}
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'error'
							})
						}
					},
					complete() {
						uni.hideLoading()
					}
				});
			},
			
			fanhui(){
				uni.navigateBack(1)
			},
			fuzhi(index){
				var that = this
				var txt = that.list.uname
				if(index == 2){
					txt = that.list.upass
				}
				if (document.queryCommandSupported('copy')) {
					let textarea = document.createElement("textarea")
					textarea.value = txt
					textarea.readOnly = "readOnly"
					document.body.appendChild(textarea)
					textarea.select() // 选中文本内容
					textarea.setSelectionRange(0, txt.length)
					let result = document.execCommand("copy")
					textarea.remove()
					uni.showToast({
						title: '复制成功'
					})
				} else {
					uni.showToast({
						title: '您的浏览器不支持',
						icon: 'error'
					})
				}
			},
			getList(){
				var that = this
				uni.request({
					url: this.global.url+'api/zy/article_detail',
					method: 'POST',
					data: {
						id: that.id
					},
					success: (res) => {
						let result = res.data
						if (result.code == 1) {
							uni.setNavigationBarTitle({
								title: result.data.title
							});
							that.list = result.data
							var mianze = result.data.disclaimer_content
							mianze = mianze.replace(/<img/gi, "<img class='richImg'");
							that.mianze = mianze
							var data = result.data.content
							data = data.replace(/<img/gi, "<img class='richImg'");
							that.data = data
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'error'
							})
						}
					},
					complete() {
						uni.hideLoading()
					}
				});
			},
		}
	}
</script>

<style>
	.richImg {
	    width: 100% !important;
	    height: auto !important;
	}
</style>
